The code works but when using printf it gives me a weird answer. Help please [closed]

Posted by user71458 on Programmers See other posts from Programmers or by user71458
Published on 2012-10-31T07:20:13Z Indexed on 2012/10/31 11:13 UTC
Read the original article Hit count: 273

Filed under:
//Programmer-William Chen
//Seventh Period                                             Computer Science II
//Problem Statement - First get the elapsed times and the program will find the
//split times for the user to see.
//
//Algorithm- First the programmer makes the prototype and calls them in the
//main function. The programmer then asks the user to input lap time data.
//Secondly, you convert the splits into seconds and subtract them so you can
//find the splits. Then the average is all the lap time's in seconds. Finally,
//the programmer printf all the results for the user to see.


#include <iostream>
#include <stdlib.h>
#include <math.h>
#include <conio.h>
#include <stdio.h>

using namespace std;

void thisgetsElapsedTimes( int &m1, int &m2, int &m3, int &m4, int &m5, int &s1, int &s2, int &s3, int &s4, int &s5); //this is prototype
void thisconvertstoseconds ( int &m1, int &m2, int &m3, int &m4, int &m5, int &s1, int &s2, int &s3, int &s4, int &s5, int &split1, int &split2, int &split3, int &split4, int &split5);//this too
void thisfindsSplits(int &m1, int &m2, int &m3, int &m4, int &m5, int &split1, int &split2, int &split3, int &split4, int &split5, int &split6, int &split7, int &split8, int &split9, int &split10);// this is part of prototype
void thisisthesecondconversation (int &split1M, int &split2M, int &split3M, int &split4M, int &split5M, int &split1S,int &split2S, int &split3S, int &split4S, int &split5S, int &split1, int &split2, int &split3, int &split4, int &split5);//this gets a value
void thisfindstheaverage(double &average, int &split1, int &split2, int &split3, int &split4, int &split5);//and this
void thisprintsstuff( int &split1M, int &split2M, int &split3M, int &split4M, int &split5M, int &split1S, int &split2S, int &split3S, int &split4S, int &split5S, double &average); //this prints
int main(int argc, char *argv[])
{
    int m1,  m2,  m3,  m4,  m5,  s1,  s2,  s3,  s4,  s5, split1,  split2,  split3,  split4,  split5,  split1M,  split2M,  split3M, split4M, split5M, split1S, split2S, split3S, split4S, split5S;
    int split6, split7, split8, split9, split10;
    double average;
    char thistakescolon;

    thisgetsElapsedTimes ( m1, m2, m3, m4, m5, s1, s2, s3, s4, s5);
    thisconvertstoseconds ( m1, m2, m3, m4, m5, s1, s2, s3, s4, s5, split1, split2, split3, split4, split5);
    thisfindsSplits ( m1, m2, m3, m4, m5, split1, split2, split3, split4, split5, split6, split7, split8, split9, split10);
    thisisthesecondconversation ( split1M, split2M, split3M, split4M, split5M, split1S, split2S, split3S, split4S, split5S, split1, split2, split3, split4, split5);
    thisfindstheaverage ( average, split1, split2, split3, split4, split5);
    thisprintsstuff ( split1M, split2M, split3M, split4M, split5M, split1S, split2S, split3S, split4S, split5S, average);
    // these are calling statements and they call from the main function to the other functions.
     system("PAUSE");         return 0;
}

void thisgetsElapsedTimes(int &m1, int &m2, int &m3, int &m4, int &m5, int &s1, int &s2, int &s3, int &s4, int &s5) { char thistakescolon; cout << "Enter the elapsed time:" << endl; cout << " Kilometer 1 "; cin >> m1 >> thistakescolon >> s1; cout << " Kilometer 2 "; cin >> m2 >> thistakescolon >> s2; cout << " Kilometer 3 " ; cin >> m3 >> thistakescolon >> s3; cout << " Kilometer 4 "; cin >> m4 >> thistakescolon >> s4; cout << " Kilometer 5 "; cin >> m5 >> thistakescolon >> s5; // this gets the data required to get the results needed for the user to see // . } void thisconvertstoseconds (int &m1, int &m2, int &m3, int &m4, int &m5, int &s1, int &s2, int &s3, int &s4, int &s5, int &split1, int &split2, int &split3, int &split4, int &split5) { split1 = (m1 * 60) + s1;//this converts for minutes to seconds for m1 split2 = (m2 * 60) + s2;//this converts for minutes to seconds for m2 split3 = (m3 * 60) + s3;//this converts for minutes to seconds for m3 split4 = (m4 * 60) + s4;//this converts for minutes to seconds for m4 split5 = (m5 * 60) + s5;//this converts for minutes to seconds for m5 }

void thisfindsSplits (int &m1, int &m2, int &m3, int &m4, int &m5,int &split1, int &split2, int &split3, int &split4, int &split5, int &split6, int &split7, int &split8, int &split9, int &split10)//this is function heading { split6 = split1; //this is split for the first lap. split7 = split2 - split1;//this is split for the second lap. split8 = split3 - split2;//this is split for the third lap. split9 = split4 - split3;//this is split for the fourth lap. split10 = split5 - split4;//this is split for the fifth lap. }

void thisfindstheaverage(double &average, int &split1, int &split2, int &split3, int &split4, int &split5) {
average = (split1 + split2 + split3 + split4 + split5)/5; // this finds the average from all the splits in seconds }

void thisisthesecondconversation (int &split1M, int &split2M, int &split3M, int &split4M, int &split5M, int &split1S,int &split2S, int &split3S, int &split4S, int &split5S, int &split1, int &split2, int &split3, int &split4, int &split5) { split1M = split1 * 60; //this finds the split times split1S = split1M - split1 * 60; //then this finds split2M = split2 * 60; //and all of this split2S = split2M - split2 * 60; //does basically split3M = split3 * 60; //the same thing split3S = split3M - split3 * 60; //all of it split4M = split4 * 60; //it's also a split4S = split4M - split4 * 60; //function split5M = split5 * 60; //and it finds the splits split5S = split5M - split5 * 60; //for each lap. }

void thisprintsstuff (int &split1M, int &split2M, int &split3M, int &split4M, int &split5M, int &split1S, int &split2S, int &split3S, int &split4S, int &split5S, double &average)// this is function heading { printf("\n kilometer 1 %d" , ":02%d",'split1M','split1S'); printf("\n kilometer 2 %d" , ":02%d",'split2M','split2S'); printf("\n kilometer 3 %d" , ":02%d",'split3M','split3S'); printf("\n kilometer 4 %d" , ":02%d",'split4M','split4S'); printf("\n kilometer 5 %d" , ":02%d",'split5M','split5S'); printf("\n your average pace is ",'average',"per kilometer \n", "William Chen\n");

 // this printf so the programmer
 // can allow the user to see
 // the results from the data gathered.

}

© Programmers or respective owner

Related posts about c++